<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>商品详情</title>
    <link rel="stylesheet" type="text/css" href="__STATIC__/css/tpshop.css" />
    <link rel="stylesheet" type="text/css" href="__STATIC__/css/jquery.jqzoom.css">
    <script src="__STATIC__/js/jquery-1.11.3.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="__PUBLIC__/js/layer/layer-min.js"></script>
    <script type="text/javascript" src="__STATIC__/js/jquery.jqzoom.js"></script>
    <script src="__PUBLIC__/js/global.js"></script>
    <script src="__PUBLIC__/js/pc_common.js"></script>
    <link rel="stylesheet" href="__STATIC__/css/location.css" type="text/css"><!-- 收货地址，物流运费 -->
</head>
<body>
<!--header-s-->
<include file="public/header" w="w1224"/>
<!--header-e-->
<div class="search-box p">
    <div class="w1224">
        <div class="search-path fl">
            <foreach name="navigate_goods" key="k" item="v">
                <a href="{:U('/Home/Goods/goodsList',array('id'=>$k))}">{$v}</a>
                <i class="litt-xyb"></i>
            </foreach>
            <div class="havedox">
                <span>{$goods.goods_name}</span>
            </div>
        </div>
    </div>
</div>
<div class="details-bigimg p">
    <div class="w1224">
        <div class="detail-img">
            <div class="product-gallery">
                <div class="product-photo" id="photoBody">
                    <!-- 商品大图介绍 start [[-->
                    <div class="product-img jqzoom">
                        <img id="zoomimg" src="{$goods.goods_id|goods_thum_images=400,400}" jqimg="{$goods.goods_id|goods_thum_images=800,800}">
                    </div>
                    <!-- 商品大图介绍 end ]]-->
                    <!-- 商品小图介绍 start [[-->
                    <div class="product-small-img fn-clear"> <a href="javascript:;" class="next-left next-btn fl disabled"></a>
                        <div class="pic-hide-box fl">
                            <ul class="small-pic" style="left:0;">
                                <foreach name="goods_images_list" item="v" key="k" >
                                    <li class="small-pic-li <if condition="$k eq 0">active</if>">
                                    <a href="javascript:;">
                                        <img src="{$v|get_sub_images=$v[goods_id],60,60}" data-img="{$v|get_sub_images=$v[goods_id],400,400}" data-big="{$v|get_sub_images=$v[goods_id],800,800}">
                                        <i></i>
                                    </a>
                                    </li>
                                </foreach>
                            </ul>
                        </div>
                        <a href="javascript:;" class="next-right next-btn fl"></a> </div>
                    <!-- 商品小图介绍 end ]]-->
                </div>
                <!-- 收藏商品 start [[-->
                <div class="collect">
                    <a href="javascript:void(0);" id="collectLink"><i class="collect-ico collect-ico-null"></i>
                        <span class="collect-text">收藏商品</span>
                        <em class="J_FavCount"></em></a>
                    <!--<a href="javascript:void(0);" id="collectLink"><i class="collect-ico collect-ico-ok"></i>已收藏<em class="J_FavCount">(20)</em></a>-->
                </div>
                <!-- 分享商品 -->
                <div class="share">
                    <div class="jiathis_style">
                        <a href="http://www.jiathis.com/share" class="jiathis jiathis_txt" target="_blank"><img src="http://v3.jiathis.com/code_mini/images/btn/v1/jiathis1.gif" border="0" /></a>
                    </div>
                    <script>
                        var jiathis_config = {
                            url:"http://{$_SERVER[HTTP_HOST]}/index.php?m=Home&c=Goods&a=goodsInfo&id={$_GET[id]}",
                            pic:"http://{$_SERVER[HTTP_HOST]}{$goods[goods_id]|goods_thum_images=400,400}",
                        }
                        var is_distribut = getCookie('is_distribut');
                        var user_id = getCookie('user_id');
                        // 如果已经登录了, 并且是分销商
                        if(parseInt(is_distribut) == 1 && parseInt(user_id) > 0)
                        {
                            jiathis_config.url = jiathis_config.url + "&first_leader="+user_id;
                        }
                    </script>
                    <script type="text/javascript" src="http://v3.jiathis.com/code_mini/jia.js" charset="utf-8"></script>
                </div>
            </div>
        </div>
        <form id="buy_goods_form" name="buy_goods_form" method="post" action="">
            <input type="hidden" name="goods_id" value="{$goods.goods_id}"><!-- 商品id -->
            <input type="hidden" name="goods_prom_type" value="{$goods.prom_type}"/><!-- 活动类型 -->
            <input type="hidden" name="shop_price" value="{$goods.shop_price}"/><!-- 活动价格 -->
            <input type="hidden" name="store_count" value="{$goods.store_count}"/><!-- 活动库存 -->
            <input type="hidden" name="market_price" value="{$goods.market_price}"/><!-- 商品原价 -->
            <input type="hidden" name="start_time" value="{$goods.start_time}"/><!-- 活动开始时间 -->
            <input type="hidden" name="end_time" value="{$goods.end_time}"/><!-- 活动结束时间 -->
            <input type="hidden" name="activity_title" value="{$goods.activity_title}"/><!-- 活动标题 -->
            <input type="hidden" name="prom_detail" value="{$goods.prom_detail}"/><!-- 促销活动的促销类型 -->
            <input type="hidden" name="activity_is_on" value=""/><!-- 活动是否正在进行中 -->
            <input type="hidden" name="item_id" value="{$Request.param.item_id}"/><!-- 商品规格id -->
            <input type="hidden" name="exchange_integral" value="{$goods.exchange_integral}"/><!-- 积分 -->
            <input type="hidden" name="point_rate" value="{$point_rate}"/><!-- 积分兑换比 -->
            <input type="hidden" name="is_virtual" value="{$goods.is_virtual}"/><!-- 是否是虚拟商品 -->
            <div class="detail-ggsl">
                <h1>{$goods.goods_name}</h1>
                <div class="presale-time" style="display: none">
                    <div class="pre-icon fl">
                        <span class="ys"><i class="detai-ico"></i><span id="activity_type">抢购活动</span></span>
                    </div>
                    <div class="pre-icon fr">
                        <span class="per" style="display: none"><i class="detai-ico"></i><em id="order_user_num">0</em>人预定</span>
                        <span class="ti" id="activity_time"><i class="detai-ico"></i>剩余时间：<span id="overTime"></span></span>
                        <span class="ti" id="prom_detail"></span>
                    </div>
                </div>
                <div class="shop-price-cou">
                    <div class="shop-price-le">
                        <ul>
                            <li class="jaj"><span id="goods_price_title">商城价：</span></li>
                            <li>
                                            <span class="bigpri_jj" id="goods_price"><em>￥</em>
                                                <!--<a href=""><em class="sale">（降价通知）</em></a>-->
                                            </span>
                            </li>
                        </ul>
<!--                         <ul>
                            <li class="jaj"><span id="market_price_title">市场价：</span></li>
                            <li class="though-line"><span><em>￥</em><span id="market_price">{$goods.market_price}</span></span></li>
                        </ul> -->
                        <ul id="activity_title_div" style="display: none">
                            <li class="jaj"><span id="activity_label"></span></li>
                            <li><span id="activity_title" style="color: #df3033;background: 0 0;border: 1px solid #df3033;padding: 2px 3px;"></span></li>
                        </ul>
                        <if condition="$goods['give_integral'] gt 0">
                            <ul>
                                <li class="jaj ls4"><span>赠送积分：</span></li>
                                <li><span class="fullminus">{$goods.give_integral}</span></li>
                            </ul>
                        </if>
                    </div>
                    <div class="shop-cou-ri">
                        <div class="allcomm"><p>累计评价</p><p class="f_blue">{$goods['comment_count']}</p></div>
                        <div class="br1"></div>
                        <div class="allcomm"><p>累计销量</p><p class="f_blue">{$goods['sales_sum']}</p></div>
                    </div>
                </div>
                <if condition="$goods[is_virtual] eq 0">
                    <div class="standard p">
                        <!-- 收货地址，物流运费 -start-->
                        <ul class="list1">
                            <li class="jaj"><span>配&nbsp;&nbsp;送：</span></li>
                            <li class="summary-stock though-line">
                                <div class="dd shd_address">
                                    <!--<div class="addrID"><div></div><b></b></div>-->
                                    <div class="store-selector add_cj_p">
                                        <div class="text" style="width: 150px;"><div></div><b></b></div>
                                        <div onclick="$(this).parent().removeClass('hover')" class="close"></div>
                                    </div>
                                    <span id="dispatching_msg" <if condition="$dispatching[status] neq 1">style="display: none;"</if>>可发货</span>
                                    <select id="dispatching_select" <empty name="$dispatching[result]">style="display: none;"</empty>>
                                    <volist name="$dispatching[result]" id="patching">
                                        <option>{$patching.shipping_name} ￥{$patching.freight}</option>
                                    </volist>
                                    </select>
                                </div>
                            </li>
                        </ul>
                        <script src="__STATIC__/js/location.js"></script>
                        <!-- 收货地址，物流运费 -end-->
                    </div>
                </if>
                <div class="standard p">
                    <ul>
                        <li class="jaj"><span>服&nbsp;&nbsp;务：</span></li>
                        <li class="lawir"><span class="service">由<a >{$tpshop_config['shop_info_store_name']}</a>发货并提供售后服务</span></li>
                    </ul>
                </div>
                <if condition="$goods['is_virtual'] eq 0 and $goods['exchange_integral'] gt 0">
                    <div class="standard p">
                        <ul>
                            <li class="jaj"><span>可&nbsp;&nbsp;用：</span></li>
                            <li class="lawir">
                                <span class="service" id="integral">
                                    {:round($goods['shop_price']-$goods['exchange_integral']/$point_rate,2)}
                                    +{$goods['exchange_integral']}积分
                                </span></li>
                        </ul>
                    </div>
                </if>

                <!-- 规格 start [[-->
                <foreach name="filter_spec" item="v" key="k">
                    <div class="spec_goods_price_div standard p">
                        <ul>
                            <li class="jaj"><span>{$k}：</span></li>
                            <li class="lawir colo">
                                <foreach name="v" item="v2" key="k2" >
                                    <input type="radio" hidden id="goods_spec_{$v2[item_id]}" name="goods_spec[{$k}]" value="{$v2[item_id]}"/>
                                    <!--<a id="goods_spec_a_{$v2[item_id]}" onclick="switch_zooming('{$v2[src]}'); select_filter(this);" <if condition="!empty($v2['src'])">onclick="$('#zoomimg').attr('src','{$v2[src]}');"</if>>{$v2[item]}</a>-->
                                    <if condition="$v2[src] neq ''">
                                        <a id="goods_spec_a_{$v2[item_id]}" onclick="switch_zooming('{$v2[src]}');select_filter(this); $('#zoomimg').attr('src','{$v2[src]}')">
                                            <img src="{$v2[src]}" style="width: 40px;height: 40px;"/>
                                            <span class="dis_alintro">{$v2[item]}</span>
                                        </a>
                                        <else/>
                                        <a id="goods_spec_a_{$v2[item_id]}" onclick="switch_zooming('{$v2[src]}'); select_filter(this);">{$v2[item]}</a>
                                    </if>
                                </foreach>
                            </li>
                        </ul>
                    </div>
                </foreach>
                <script>

                </script>
                <!-- 规格end ]]-->
                <div class="standard">
                    <ul class="p">
                        <li class="jaj"><span>数&nbsp;&nbsp;量：</span></li>
                        <li class="lawir">
                            <div class="minus-plus">
                                <a class="mins" href="javascript:void(0);" onclick="altergoodsnum(-1)">-</a>
                                <input class="buyNum" id="number" type="text" name="goods_num" value="1" onblur="altergoodsnum(0)" max=""/>
                                <a class="add" href="javascript:void(0);" onclick="altergoodsnum(1)">+</a>

                            </div>

                            <div class="sav_shop">{$goods['goods_dw']} &nbsp;|库存：<span id="spec_store_count">{$goods['store_count']}</span></div>
                        </li>
                    </ul>
                </div>
                <div class="standard">
                    <ul class="p">
                        <li class="jaj"><span>规&nbsp;&nbsp;格：</span></li>
                        <li class="lawir">
                            <div class="sav_shop"><span id="spec_store_count" style="color:red">{$goods['goods_gg']}</span></div>
                        </li>
                    </ul>
                </div>
                <div class="standard">
                    <ul class="p">
                        <li class="jaj"><span>型&nbsp;&nbsp;号：</span></li>
                        <li class="lawir">
                            <div class="sav_shop"><span id="spec_store_count" style="color:red">{$goods['goods_xh']}</span></div>
                        </li>
                    </ul>
                </div>
                <div class="standard p">
                    <input type="hidden" name="goods_id" value="{$goods.goods_id}" />
                    <if condition="$goods[is_virtual] eq 1">
                        <input type="hidden" name="virtual_limit" id="virtual_limit" value="{$goods.virtual_limit}"/>
                        <a class="paybybill" href="javascript:;" onclick="virtual_buy();">立即购买</a>
                    <elseif condition="$goods['exchange_integral'] gt 0"/>
                        <a id="join_cart_now" class="paybybill" href="javascript:;"  onclick="buyIntegralGoods({$goods.goods_id},1);">立即兑换</a>
                        <a id="no_join_cart_now" class="paybybill" style="display:none;background: #ebebeb;color: #999;cursor: not-allowed">立即兑换</a>
                    <else/>
                        <a id="join_cart_now" class="paybybill" href="javascript:;" onclick="buy_now();">立即购买</a>
                        <a id="join_cart" class="addcar" href="javascript:;" onclick="AjaxAddCart({$goods.goods_id},1);"><i class="sk"></i>加入购物车</a>
                        <a id="no_join_cart_now" class="paybybill" style="display:none;background: #ebebeb;color: #999;cursor: not-allowed">立即购买</a>
                        <a id="no_join_cart" class="addcar" style="display:none;background: #ebebeb;color: #999;cursor: not-allowed"><i class="sk"></i>加入购物车</a>
                    </if>
                </div>
            </div>
        </form>
        <!--看了又看-s-->
        <div class="detail-ry p">
            <div class="type_more" >
                <div class="type-top">
                    <h2>看了又看<a class="update_h fr" href="javascript:;" onclick="replace_look();">换一换</a></h2>
                </div>
                <div id="see_and_see">
                </div>
            </div>
        </div>
        <!--看了又看-s-->
    </div>
</div>
<div class="detail-main p">
    <div class="w1224">
        <div class="deta-le-ma">
            <div class="type_more">
                <div class="type-top">
                    <h2>热搜推荐</h2>
                </div>
                <div class="type-bot">
                    <ul class="xg_typ">
                        <foreach name="tpshop_config.hot_keywords" item="wd" key="k">
                            <li><a href="{:U('Home/Goods/search',array('q'=>$wd))}">{$wd}</a></li>
                        </foreach>
                    </ul>
                </div>
            </div>
            <div class="type_more ma-to-20">
                <div class="type-top">
                    <h2>推荐热卖</h2>
                </div>
                <div class="tjhot-shoplist type-bot">
                    <tpshop sql="select goods_id,goods_name,shop_price from __PREFIX__goods where is_recommend=1 and is_on_sale = 1 order by goods_id desc limit 10" item="vo" key="k">
                        <div class="alone-shop">
                            <a href="{:U('Home/Goods/goodsInfo',array('id'=>$vo[goods_id]))}"><img src="{$vo.goods_id|goods_thum_images=206,206}" style="display: inline;"></a>
                            <p class="line-two-hidd"><a href="{:U('Home/Goods/goodsInfo',array('id'=>$vo[goods_id]))}">{$vo.goods_name|getSubstr=0,30}</a></p>
                            <p class="price-tag"><span class="li_xfo">￥</span><span>{$vo.shop_price}</span></p>
                            <!--<p class="store-alone"><a href="">恒要达食品专享店</a></p>-->
                        </div>
                    </tpshop>
                </div>
            </div>
        </div>
        <div class="deta-ri-ma">
            <div class="introduceshop">
                <div class="datail-nav-top">
                    <ul>
                        <li class="red"><a href="javascript:void(0);">商品介绍</a></li>
                        <li><a href="javascript:void(0);">规格及包装</a></li>
                    </ul>
                </div>
                <!--<div class="he-nav"></div>-->
                <div class="shop-describe shop-con-describe p">
                    <div class="deta-descri">
                        <p class="shopname_de"><span>商品名称：</span><span>{$goods.goods_name}</span></p>
                        <div class="ma-d-uli p">
                            <ul>
                                <!--<li><span>品牌：</span><span>{$goods['brand_name']}</span></li>-->
                                <li><span>货号：</span><span>{$goods.goods_sn}</span></li>
                                <foreach name="goods_attr_list" item="v" key="k" >
                                    <li><span>{$goods_attribute[$v[attr_id]]}：</span><span>{$v[attr_value]}</span></li>
                                </foreach>
                            </ul>
                        </div>
                        <p class="shopname_de"><span>品牌：</span><span>{$goods.brand}</span></p>
                        <p class="shopname_de"><span>产地：</span><span>{$goods.goods_cd}</span></p>
                        <p class="shopname_de"><span>注册证号：</span><span>{$goods.goods_zczh}</span></p>
                        <p class="shopname_de"><span>供应商：</span><span>{$supp}</span></p>
                        
                        <!-- <p class="shopname_de"><span>产地：</span><span>{$goods.goods_cd}</span></p> -->
                        <div class="moreparameter">
                            <!--
                            <a href="">跟多参数<em>>></em></a>
                            -->
                        </div>
                    </div>
                    <div class="detail-img-b">
                        {$goods.goods_content|htmlspecialchars_decode}
                    </div>
                </div>
                <div class="shop-describe shop-con-describe p" style="display: none;">
                    <div class="deta-descri">
                        <!--
                        <p class="shopname_de"><span>如果您发现商品信息不准确，<a class="de_cb" href="">欢迎纠错</a></span></p>
                        -->
                        <h2 class="shopname_de">属性</h2>
                        <foreach name="goods_attr_list" item="v" key="k">
                            <div class="twic_a_alon">
                                <p class="gray_t">{$goods_attribute[$v[attr_id]]}</p>
                                <p>{$v[attr_value]}</p>
                            </div>
                        </foreach>
                    </div>
                </div>


            </div>
        </div>
    </div>
</div>
<!--footer-s-->
<include file="public/footer" />
<include file="public/sidebar_cart" />
<!--看了又看-s-->
<div style="display: none" id="look_see">
    <foreach name="look_see" item="look" key="k">
        <div class="tjhot-shoplist type-bot">
            <div class="alone-shop">
                <a href="{:U('Home/Goods/goodsInfo',array('id'=>$look[goods_id]))}"><img class="wiahides" src="{$look.goods_id|goods_thum_images=206,206}" style="display: inline;"></a>
                <p class="shop_name2">
                    <a href="{:U('Home/Goods/goodsInfo',array('id'=>$look[goods_id]))}">{$look.goods_name}</a>
                </p>
                <p class="price-tag">
                    <span class="li_xfo">￥</span><span>{$look.shop_price*0.15}</span>
                </p>
            </div>
        </div>
    </foreach>
    <!--看了又看-s-->
</div>
<!--footer-e-->
<script src="__STATIC__/js/lazyload.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="__STATIC__/js/headerfooter.js" ></script>
<script type="text/javascript">
    var commentType = 1;// 默认评论类型
    var spec_goods_price = {$spec_goods_price|default='null'};//规格库存价格
    $(document).ready(function () {
        /*商品缩略图放大镜*/
        $(".jqzoom").jqueryzoom({
            xzoom: 500,
            yzoom: 500,
            offset: 1,
            position: "right",
            preload: 1,
            lens: 1
        });
        replace_look();
        initBuy();
        initSpec();
        initGoodsPrice();
    });
    /**
     * 购买初始化
     */
    function initBuy(){
        var is_virtual = $("input[name='is_virtual']").val();
        var buy_url;
        if(is_virtual == 1){
            buy_url = "{:U('Home/Virtual/buy_virtual')}";
        }else{
            buy_url = "{:U('Home/Cart/cart2',['action'=>'buy_now'])}";
        }
        $('#buy_goods_form').attr('action',buy_url);

    }
    //有规格id的时候，解析规格id选中规格
    function initSpec(){
        var item_id = $("input[name='item_id']").val();
        $.each(spec_goods_price,function(i, o){
            if(o.item_id == item_id){
                var spec_key_arr = o.key.split("_");
                $.each(spec_key_arr,function(index,item){
                    var spec_radio = $("#goods_spec_"+item);
                    var goods_spec_a = $("#goods_spec_a_"+item);
                    spec_radio.attr("checked","checked");
                    goods_spec_a.addClass('red');
                })
            }
        })
        if(item_id > 0 && !$.isEmptyObject(spec_goods_price)){
            var item_arr = [];
            $.each(spec_goods_price,function(i, o){
                item_arr.push(o.item_id);
            })
            //规格id不存在商品里
            if($.inArray(parseInt(item_id), item_arr) < 0){
                initFirstSpec();
            }else{
                $.each(spec_goods_price,function(i, o){
                    if(o.item_id == item_id){
                        var spec_key_arr = o.key.split("_");
                        $.each(spec_key_arr,function(index,item){
                            var spec_radio = $("#goods_spec_"+item);
                            var goods_spec_a = $("#goods_spec_a_"+item);
                            spec_radio.attr("checked","checked");
                            goods_spec_a.addClass('red');
                        })
                    }
                })
            }
        }else{
            initFirstSpec();
        }
    }

    //默认让每种规格第一个选中
    function initFirstSpec(){
        $('.spec_goods_price_div').each(function (i, o) {
            var firstSpecRadio = $(this).find("input[type='radio']").eq(0);
            firstSpecRadio.attr('checked','checked').prop('checked','checked');
            firstSpecRadio.parent().find('a').eq(0).addClass('red');
        })
    }

    /**
     * 切换规格
     */
    function select_filter(obj)
    {
        $(obj).addClass('red').siblings('a').removeClass('red');
        $(obj).siblings('input').removeAttr('checked');
        $(obj).prev('input').attr('checked','checked').prop('checked','checked');
        // 更新商品价格
        initGoodsPrice();
    }

    //看了又看切换
    var tmpindex = 0;
    var look_see_length = $('#look_see').children().length;
    function replace_look(){
        var listr='';
        if(tmpindex*2>=look_see_length) tmpindex = 0;
        $('#look_see').children().each(function(i,o){
            if((i>=tmpindex*2) && (i<(tmpindex+1)*2)){
                listr += '<div class="tjhot-shoplist type-bot">'+$(o).html()+'</div>';
            }
        });
        tmpindex++;
        $('#see_and_see').empty().append(listr);
    }
    //缩略图切换
    $('.small-pic-li').each(function (i, o) {
        var lilength = $('.small-pic-li').length;
        $(o).hover(function () {
            $(o).siblings().removeClass('active');
            $(o).addClass('active');
            $('#zoomimg').attr('src', $(o).find('img').attr('data-img'));
            $('#zoomimg').attr('jqimg', $(o).find('img').attr('data-big'));

            $('.next-btn').removeClass('disabled');
            if (i == 0) {
                $('.next-left').addClass('disabled');
            }
            if (i + 1 == lilength) {
                $('.next-right').addClass('disabled');
            }
        });
    })

    //前一张缩略图
    $('.next-left').click(function () {
        var newselect = $('.small-pic>.active').prev();
        $('.small-pic>.active').removeClass('active');
        $(newselect).addClass('active');
        $('#zoomimg').attr('src', $(newselect).find('img').attr('data-img'));
        $('#zoomimg').attr('jqimg', $(newselect).find('img').attr('data-big'));
        var index = $('.small-pic>li').index(newselect);
        if (index == 0) {
            $('.next-left').addClass('disabled');
        }
        $('.next-right').removeClass('disabled');
    })

    //后前一张缩略图
    $('.next-right').click(function () {
        var newselect = $('.small-pic>.active').next();
        $('.small-pic>.active').removeClass('active');
        $(newselect).addClass('active');
        $('#zoomimg').attr('src', $(newselect).find('img').attr('data-img'));
        $('#zoomimg').attr('jqimg', $(newselect).find('img').attr('data-big'));
        var index = $('.small-pic>li').index(newselect);
        if (index + 1 == $('.small-pic>li').length) {
            $('.next-right').addClass('disabled');
        }
        $('.next-left').removeClass('disabled');
    })
    $(function(){
        $("#area").click(function (e) {
            SelCity(this,e);
        });
    })

    $(function() {
        ajaxComment(1,1);
        // 好评差评 切换
        $('.cte-deta ul li').click(function(){
            $(this).addClass('red').siblings().removeClass('red');
            commentType = $(this).data('t');// 评价类型   好评 中评  差评
            ajaxComment(commentType,1);
        })
    });
    $(function(){
        $('.datail-nav-top ul li').click(function(){
            $(this).addClass('red').siblings().removeClass('red');
            var er = $('.datail-nav-top ul li').index(this);
            $('.shop-con-describe').eq(er).show().siblings('.shop-con-describe').hide();
        })
    })

    /**
     * 加减数量
     * n 点击一次要改变多少
     * maxnum 允许的最大数量(库存)
     * number ，input的id
     */
    function altergoodsnum(n){
        var num = parseInt($('#number').val());
        var maxnum = parseInt($('#number').attr('max'));
        if(maxnum > 200){
            maxnum = 200;
        }
        num += n;
        num <= 0 ? num = 1 :  num;
        if(num >= maxnum){
            $(this).addClass('no-mins');
            num = maxnum;
        }
        $('#store_count').text(maxnum-num); //更新库存数量
        $('#number').val(num);
        initGoodsPrice();
    }

    //初始化商品价格库存
    function initGoodsPrice() {
        var goods_id = $('input[name="goods_id"]').val();
        var goods_num = parseInt($('#number').val());
        if (!$.isEmptyObject(spec_goods_price)) {
            var goods_spec_arr = [];
            $("input[name^='goods_spec']").each(function () {
                if($(this).attr('checked') == 'checked'){
                    goods_spec_arr.push($(this).val());
                }
            });
            var spec_key = goods_spec_arr.sort(sortNumber).join('_');  //排序后组合成 key
            var item_id = spec_goods_price[spec_key]['item_id'];
            $('input[name=item_id]').val(item_id);
        }
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: {goods_id: goods_id, item_id: item_id, goods_num : goods_num},
            url: "{:U('Home/Goods/activity')}",
            success: function (data) {
                if (data.status == 1) {
                    $('input[name="goods_prom_type"]').attr('value', data.result.goods.prom_type);//商品活动类型
                    $('input[name="shop_price"]').attr('value', data.result.goods.shop_price);//商品价格
                    $('input[name="store_count"]').attr('value', data.result.goods.store_count);//商品库存
                    $('input[name="market_price"]').attr('value', data.result.goods.market_price);//商品原价
                    $('input[name="start_time"]').attr('value', data.result.goods.start_time);//活动开始时间
                    $('input[name="end_time"]').attr('value', data.result.goods.end_time);//活动结束时间
                    $('input[name="activity_title"]').attr('value', data.result.goods.activity_title);//活动标题
                    $('input[name="prom_detail"]').attr('value', data.result.goods.prom_detail);//促销详情
                    $('input[name="activity_is_on"]').attr('value', data.result.goods.activity_is_on);//活动是否正在进行中
                    goods_activity_theme();
                }
            }
        });
    }

    //商品价格库存显示
    function goods_activity_theme(){
        var goods_prom_type = $('input[name="goods_prom_type"]').attr('value');
        var activity_is_on = $('input[name="activity_is_on"]').attr('value');
        if(activity_is_on == 0){
            setNormalGoodsPrice();
        }else{
            if(goods_prom_type == 0){
                //普通商品
                setNormalGoodsPrice();
            }else if(goods_prom_type == 1){
                //抢购
                setFlashSaleGoodsPrice();
            }else if(goods_prom_type == 2){
                //团购
                setGroupByGoodsPrice();
            }else if(goods_prom_type == 3){
                //优惠促销
                setPromGoodsPrice();
            }else{

            }
        }
        var buy_num  = parseInt($('#number').val());//购买数
        var store = parseInt($('input[name="store_count"]').val());//实际库存数量
        if(store<= 0){
            joinCart(false);
        }else{
            joinCart(true);
        }
        if(buy_num > store){
            $('.buyNum').val(store);
        }
    }

    //普通商品库存和价格
    function setNormalGoodsPrice(){
        var goods_price,store_count;//商品价,商品库存
        var market_price =  $("input[name='market_price']").attr('value');// 商品市场价
        var exchange_integral = $("input[name='exchange_integral']").attr('value');// 兑换积分
        var point_rate = $("input[name='point_rate']").attr('value');// 积分金额比
        // 如果有属性选择项
        if(!$.isEmptyObject(spec_goods_price))
        {
            var goods_spec_arr = [];
            $("input[name^='goods_spec']").each(function () {
                if($(this).attr('checked') == 'checked'){
                    goods_spec_arr.push($(this).val());
                }
            });
            var spec_key = goods_spec_arr.sort(sortNumber).join('_');  //排序后组合成 key
            goods_price = spec_goods_price[spec_key]['price']*0.15; // 找到对应规格的价格
            store_count = spec_goods_price[spec_key]['store_count']; // 找到对应规格的库存
            $("input[name='shop_price']").attr('value',goods_price);
            $("input[name='store_count']").attr('value',store_count);
        }
        goods_price =  $("input[name='shop_price']").attr('value')*0.15;// 商品本店价
        store_count = $("input[name='store_count']").attr('value');// 商品库存
        $('#market_price_title').empty().html('市场价：');
        $('#market_price').empty().html(market_price);
        $("#goods_price").html("<em>￥</em>"+goods_price); //变动价格显示
        var integral = round(goods_price - (exchange_integral / point_rate),2);
        $("#integral").html(integral + '+' +exchange_integral + '积分'); //积分显示
        $('#spec_store_count').html(store_count);
        $('.presale-time').hide();
        $('#number').attr('max',store_count);
    }

    //秒杀商品库存和价格
    function setFlashSaleGoodsPrice(){
        var flash_sale_price = $("input[name='shop_price']").attr('value');
        var flash_sale_count = $("input[name='store_count']").attr('value');
        var market_price = $("input[name='market_price']").attr('value');
        var start_time = $("input[name='start_time']").attr('value');
        var end_time = $("input[name='end_time']").attr('value');
        var activity_title = $("input[name='activity_title']").attr('value');
        $("#goods_price").html("<em>￥</em>"+flash_sale_price); //变动价格显示
        $('#spec_store_count').html(flash_sale_count);
        $('#goods_price_title').html('抢购价：');
        $('#market_price_title').empty().html('原&nbsp;&nbsp;价：');
        $('#activity_label').empty().html('抢&nbsp;&nbsp;购：');
        $('#activity_title').empty().html(activity_title);
        $('#activity_title_div').show();
        $('#market_price').empty().html(market_price);
        $('.presale-time').show();
        $('#prom_detail').hide();
        $('#number').attr('max',flash_sale_count);
        setInterval(activityTime, 1000);
    }

    //团购商品库存和价格
    function setGroupByGoodsPrice(){
        var group_by_price = $("input[name='shop_price']").attr('value');
        var group_by_count = $("input[name='store_count']").attr('value');
        var market_price = $("input[name='market_price']").attr('value');
        var start_time = $("input[name='start_time']").attr('value');
        var end_time = $("input[name='end_time']").attr('value');
        var activity_title = $("input[name='activity_title']").attr('value');
        $("#goods_price").empty().html("<em>￥</em>"+group_by_price); //变动价格显示
        $('#spec_store_count').empty().html(group_by_count);
        $('#activity_type').empty().html('团购');
        $('#goods_price_title').empty().html('团购价：');
        $('#market_price_title').empty().html('原&nbsp;&nbsp;价：');
        $('#activity_label').empty().html('团&nbsp;&nbsp;购：');
        $('#activity_title').empty().html(activity_title);
        $('#activity_title_div').show();
        $('#market_price').empty().html(market_price);
        $('.presale-time').show();
        $('#prom_detail').hide();
        $('#number').attr('max',group_by_count);
        setInterval(activityTime, 1000);
    }

    //促销商品库存和价格
    function setPromGoodsPrice(){
        var prom_goods_price = $("input[name='shop_price']").attr('value');
        var prom_goods_count = $("input[name='store_count']").attr('value');
        var market_price = $("input[name='market_price']").attr('value');
        var start_time = $("input[name='start_time']").attr('value');
        var end_time = $("input[name='end_time']").attr('value');
        var activity_title = $("input[name='activity_title']").attr('value');
        var prom_detail = $("input[name='prom_detail']").attr('value');
        $("#goods_price").empty().html("<em>￥</em>"+prom_goods_price); //变动价格显示
        $('#spec_store_count').empty().html(prom_goods_count);
        $('#activity_type').empty().html('促销');
        $('.presale-time').show();
        $('#prom_detail').empty().html(prom_detail).show();
        $('#activity_time').hide();
        $('#goods_price_title').empty().html('促销价：');
        $('#market_price_title').empty().html('原&nbsp;&nbsp;价：');
        $('#activity_label').empty().html('促&nbsp;&nbsp;销：');
        $('#activity_title').empty().html(activity_title);
        $('#activity_title_div').show();
        $('#market_price').empty().html(market_price);
        $('#number').attr('max',prom_goods_count);
    }

    // 倒计时
    function activityTime() {
        var end_time = parseInt($("input[name='end_time']").attr('value'));
        var timestamp = Date.parse(new Date());
        var now = timestamp/1000;
        var end_time_date = formatDate(end_time*1000);
        var text = GetRTime(end_time_date);
        //活动时间到了就刷新页面重新载入
        if(now > end_time){
            layer.msg('该商品活动已结束',function(){
                location.reload();
            });
        }
        $("#overTime").text(text);
    }
    //时间戳转换
    function add0(m){return m<10?'0'+m:m }
    function  formatDate(now)   {
        var time = new Date(now);
        var y = time.getFullYear();
        var m = time.getMonth()+1;
        var d = time.getDate();
        var h = time.getHours();
        var mm = time.getMinutes();
        var s = time.getSeconds();
        return y+'/'+add0(m)+'/'+add0(d)+' '+add0(h)+':'+add0(mm)+':'+add0(s);
    }

    /***用作 sort 排序用*/
    function sortNumber(a,b)
    {
        return a - b;
    }
    /**
     * 立即购买
     */
    function buy_now(){
        if(getCookie('user_id') == ''){
            pop_login();
            return false;
        }
        var store_count = $("input[name='store_count']").attr('value');// 商品原始库存
        var buyNum = parseInt($("input[name='goods_num']").val());
        if (buyNum <= store_count) {
            $('#buy_goods_form').submit();
        } else {
            layer.msg('购买数量超过此商品购买上限', {icon: 3});
        }
    }
    /***收藏商品**/
    $('#collectLink').click(function(){
        if(getCookie('user_id') == ''){
            layer.msg('请先登录！', {icon: 1});
        }else{
            $.ajax({
                type:'post',
                dataType:'json',
                data:{goods_id:$('input[name="goods_id"]').val()},
                url:"{:U('Home/Goods/collect_goods')}",
                success:function(res){
                    if(res.status == 1){
                        layer.msg('成功添加至收藏夹', {icon: 1});
                    }else{
                        layer.msg(res.msg, {icon: 3});
                    }
                }
            });
        }
    });
    function virtual_buy() {
        var store_count = $("input[name='store_count']").attr('value');// 商品原始库存
        var buynum = parseInt($('.buyNum').val());
        var virtual_limit = parseInt($('#virtual_limit').val());
        if ((buynum <= store_count && buynum <= virtual_limit) || (buynum < store_count && virtual_limit == 0)) {
            $('#buy_goods_form').submit();
        } else {
            layer.msg('购买数量超过此商品购买上限', {icon: 3});
        }
    }
    /***用ajax分页显示评论**/
    function ajaxComment(commentType,page){
        $.ajax({
            type : "GET",
            url:"/index.php?m=Home&c=goods&a=ajaxComment&goods_id={$goods['goods_id']}&commentType="+commentType+"&p="+page,//+tab,
            success: function(data){
                $("#ajax_comment_return").html('').append(data);
            }
        });
    }
    /**
     * 切换图片
     */
    function switch_zooming(img)
    {
        if(img != ''){
            $('#zoomimg').attr('jqimg', img).attr('src', img);
        }
    }
</script>
<!--商品咨询JS-->
<script>
    // 普通 图形验证码
    function verify(){
        $('#verify_code').attr('src','/index.php?m=Home&c=User&a=verify&type=consult&r='+Math.random());
    }
    var consult=$('#consult-h');
    consult.find('.consult-item').eq(0).addClass('consult-ac');
    consult.find('.consult-menus>a').click(function () {
        $(this).addClass('consult-ac').siblings().removeClass('consult-ac');
        consult.find('.consult-item').eq($(this).index())
                .addClass('consult-ac').siblings().removeClass('consult-ac');
        $('.check-consult-tpye').find('a').eq($(this).index())
    });
    $(document).ready(function () {
        verify();
    });
    $(document).on('click','.pagination  a',function(){
        var page = $(this).data('p');
        var type = $('#type').val();
        getconsult(type,page)
    });
    /**
     * 获取商品咨询
     * @param type  //咨询类型
     * @param page  //分页
     */
    function getconsult(type,page){
        var goods_id = {$goods.goods_id};
        var url = "/index.php?m=Home&c=Goods&a=ajax_consult";
        $.ajax({
            type : "Post",
            url  : url,
            data : {goods_id:goods_id,consult_type:type,p:page},
            dataType: "html",
            success: function(data){
                $('#consult_content').html('');
                $('#consult_content').append(data);
            }
        });
    }
</script>
</body>
</html>